<template>
    <el-dialog :title="'修改客户信息'"
               :close-on-click-modal="false"
               :visible.sync="visible">
        <el-form :model="dataForm"
                 :rules="dataRule"
                 ref="dataForm"
                 @keyup.enter.native="dataFormSubmit()"
                 label-width="120px">
            <el-form-item label="CRM客户代码" prop="custCode">
                <el-input v-model="dataForm.custCode" disabled></el-input>
            </el-form-item>
            <el-form-item label="ERP客户代码" prop="biz1">
                <el-input v-model="dataForm.biz1" disabled></el-input>
            </el-form-item>
            <el-form-item label="客户名称" prop="custName">
                <el-input v-model="dataForm.custName" disabled></el-input>
            </el-form-item>
            <el-row>
                <el-col :span="8">
                    <el-form-item label="客户行业"
                                  prop="custType">
                        <el-select v-model="dataForm.custType" placeholder="请选择">
                            <el-option
                                v-for="item in cusIndustryList"
                                :key="item.industryName"
                                :label="item.industryName"
                                :value="item.industryName">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="去年级别"
                                  prop="dbiz1">
                        <el-select v-model="dataForm.dbiz1" placeholder="请选择">
                            <el-option
                                v-for="item in custLevelList"
                                :key="item.levelCode"
                                :label="item.levelCode"
                                :value="item.levelCode">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="当前级别"
                                  prop="dbiz2">
                        <el-select v-model="dataForm.dbiz2" placeholder="请选择">
                            <el-option
                                v-for="item in custLevelList"
                                :key="item.levelCode"
                                :label="item.levelCode"
                                :value="item.levelCode">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-form-item label="年销售额" prop="dbiz3">
                <el-input v-model="dataForm.dbiz3" disabled></el-input>
            </el-form-item>
            <el-form-item label="升级时间" prop="biz3">
                <el-input v-model="dataForm.biz3" disabled></el-input>
            </el-form-item>
            <el-form-item label="负责人" prop="custManName">
                <el-input v-model="dataForm.custManName" disabled></el-input>
            </el-form-item>
        </el-form>
        <span slot="footer"
              class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary"
                 @click="dataFormSubmit()">确定</el-button>
    </span>
    </el-dialog>
</template>

<script>
import { Debounce } from '@/utils/debounce'
import {custTypeList,departList} from '@/utils/data'
export default {
	data () {
		return {
			visible: false,
            custTypeList: custTypeList,
            departList: departList,
            provinceList: [],
            cityList: [],
            areaList: [],
			roleList: [],
            personList: [],
            cusIndustryList: [],
            custLevelList: [],
			dataForm: {
                custCode: "",
                biz1: "",
                custName: "",
                custType: "",
                dbiz1: "",
                dbiz2: "",
                dbiz3: "",
                biz3: "",
                custManName: "",
			},
			dataRule: {
			}
		}
	},
	methods: {
		init (row) {
			this.visible = true
            this.getPersonList()
            this.dataForm = row;
		},
        getPersonList(){
            this.$http({
                url: this.$http.adornUrl('/crm/base/cusIndustry/page'),
                method: 'get',
                params: this.$http.adornParams(
                    Object.assign(
                        {
                            current: 1,
                            size: 99
                        },
                    )
                )
            }).then(({data}) => {
                this.cusIndustryList = data.obj.records
                
            })
            this.$http({
                url: this.$http.adornUrl('/crm/base/custLevel/page'),
                method: 'get',
                params: this.$http.adornParams(
                    Object.assign(
                        {
                            current: 1,
                            size: 99
                        },
                    )
                )
            }).then(({data}) => {
                this.custLevelList = data.obj.records
                
            })
        },
        
		// 表单提交
		dataFormSubmit: Debounce(function () {
			this.$refs['dataForm'].validate((valid) => {
				if (valid) {
					this.$http({
						url: this.$http.adornUrl(this.dataForm.id ? '/crm/base/cust/updbyid' : '/crm/base/cust/saveCust'),
						method: 'post',
						data: this.$http.adornData({
                            ...this.dataForm
                        })
					}).then(({ data }) => {
						this.$message({
							message: '操作成功',
							type: 'success',
							duration: 1500,
							onClose: () => {
								this.visible = false
								this.$emit('refreshDataList')
							}
						})
					})
				}
			})
		})
	}
}
</script>
